<template>
  <el-container class="home_container">
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '60px' : '170px'">
        <!-- 菜单栏 -->
        <el-menu background-color="#35505f" text-color="#fff" unique-opened :collapse-transition="false" :collapse="isCollapse" router :default-active="activePath">
          <el-header class="menu-header"><span v-if="!isCollapse">电商后台管理系统</span>
          </el-header>

          <el-submenu popper-class="popperspan" index='/home'>
            <template slot="title">
              <i :class="menuIcon[145]"></i>
              <span slot="title">信息总览</span>
            </template>

            <el-menu-item-group>
              <el-menu-item index="/home/welcome" @click="setNavState('/home/welcome')" style="paddingLeft:47px">首页</el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-submenu popper-class="popperspan" v-for="item in menusList" :key="item.id" :index="item.id + ''">
            <template slot="title">
              <i :class="menuIcon[item.id]"></i>
              <span slot="title">{{ item.authName }}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item style="paddingLeft:47px" v-for="item1 in item.children" :key="item1.id" :index="'/home/'+item1.path + ''" @click="setNavState('/home/'+item1.path)">{{ item1.authName }}</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右边内容主体 -->
      <el-main>
        <!-- 头部区域 -->
        <el-header>
          <img class="headerMenu" src="../assets/img/menu.png" @click="toggleCollapase" />

          <div style=" display: flex;align-items: center;marginRight:10px">
            <span style="fontSize:13px;color:rgb(24, 23, 23);marginRight:15px">你好, 管理员</span>
            <el-popover placement="bottom">
              <div style=" display: flex;flex-direction:column;justify-content: space-around;align-items: center;height:80px">
                <el-button size="mini" type="text" @click="$mess('暂未开发','warning')">个人管理</el-button>
                <el-button type="primary" size="mini" @click="outLogin" style="marginLeft:5px">退出</el-button>
              </div>
              <img slot="reference" style="width: 35px; border-radius: 50%;cursor: pointer" src="../assets/img/toux.png" />
            </el-popover>
          </div>
        </el-header>

        <router-view class="routerview" />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      isCollapse: false,
      menusList: null,
      menuIcon: {
        125: 'iconfont icon-users',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao',
      },
      activePath: '', //被激活的链接地址
    }
  },
  created() {
    this.getmenus()
    this.activePath = window.sessionStorage.getItem('NavState')
  },
  methods: {
    outLogin() {
      window.sessionStorage.clear('token') //清空token
      this.$router.push('/login') //跳到登录界面
    },
    getmenus() {
      this.$http.get('menus').then((res) => {
        if (res.status !== 200) return
        this.menusList = res.data.data.slice(0, 4)
      })
    },
    toggleCollapase() {
      this.isCollapse = !this.isCollapse
    },
    setNavState(val) {
      window.sessionStorage.setItem('NavState', val)
      this.activePath = val
    },
  },
}
</script>

<style lang="less" scoped>
.home_container {
  height: 100%;
  .el-aside {
    background-color: #35505f;
    overflow: visible;
    .menu-header {
      background-color: #35505f;
      margin-bottom: 45px;
    }
    .el-submenu {
      // width: 180px;
      i {
        margin-right: 10px;
      }
      .el-menu-item {
        min-width: 0;
      }
    }
  }

  .el-header {
    background-color: #f3f3f3;

    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    .headerMenu {
      width: 30px;
      cursor: pointer;

      margin-left: -7px;
    }
  }

  .el-main {
    padding: 0;
    margin: 0;
  }
}

.el-menu {
  width: 100%;
}
.popperspan {
  font-size: 50px;
  
}
.routerview {
  margin: 20px 0 0 15px;
}
</style>
